/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Thu 09 Jul 2020 11:39:47 AM CST
 * Destription:  测试srand 和rand
 */
#include <algorithm>
#include <iostream>
#include <iterator>
#include <random>
#include <set>
#include <stdlib.h>
#include <string>

/**
 * @brief 测试set 乱序
 *
 */
void test_rand_set()
{
//    std::vector<std::string> v = { "aa", "bb", "cc"};
    std::set<std::string> v;
    v.insert("aa");
    v.insert("bb");
    v.insert("cc");

    //std::random_device rd;
    //std::mt19937 g(rd());
    std::random_shuffle(v.begin(), v.end());
    std::cout << "vector 随机化:";
    std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, " "));
    std::cout << "\n";

}

/**
 * @brief 测试vector 乱序
 *
 */
void test_rand_vector()
{
    std::vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    std::random_device rd;
    std::mt19937 g(rd());
    std::shuffle(v.begin(), v.end(), g);
    std::cout << "vector 随机化:";
    std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << "\n";
}

int main(int argc, char* argv[])
{
    srand(time(NULL));
    std::cout << "rand_max= " << RAND_MAX << std::endl;
    std::cout << "rand value1= " << rand() << std::endl;
    test_rand_vector();
    test_rand_set();
    return 0;
}
